package com.model.servlet;

import com.aliyuncs.exceptions.ClientException;
import com.model.tool.SmsDemo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;



/**
 * Servlet implementation class SmsServlet
 */
@WebServlet("/SmsServlet")
public class SmsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SmsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置请求内容格式
		request.setCharacterEncoding("utf-8");
		//设置响应内容格式
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html chatset=utf-8");
		//接收前台传入的手机号
		String phone=request.getParameter("phone");
		System.out.println("前台输入的手机号为："+phone);
		//发送短信
		SmsDemo s=new SmsDemo();
		try {
			SmsDemo.sendSms(phone);
		} catch (ClientException e) {
			
			e.printStackTrace();
		}
		System.out.println(SmsDemo.code);
		response.getWriter().write(SmsDemo.code);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
